package com.lxyk.mapper;

import com.lxyk.pojo.Admin;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface AdminMapper {

    /*有一次写完接口还是报错 因为这是接口 必须改成interface*/
    //注册
    @Insert("insert into admin values(null,#{username},#{password},0,#{code},null,#{email})")
    Integer addAdmin(Admin admin);

    //更新 这里的注解如果太长要换行 会自动帮你拼接
    @Update("update admin set username=#{username},password=#{password},status=#{status},code=#{code},phone=#{phone}" +
            ", email=#{email} where id=#{id}")
    Integer update(Admin admin);

    //校验用户名是否存在 存在返回1 不存在返回0
    @Select("select count(id) from admin where username=#{username}")
    Integer checkUserName(String username);

    //激活查询账号
    @Select("select * from admin where code=#{code}")
    Admin findByCode(String code);

    //登录
    @Select("select * from admin where username=#{username} and password=#{password} and status=1")
    Admin login(Admin admin);
}
